﻿Imports System.Threading.Tasks

Public Class Salon
    Private m_CreatedBy As String
    Private m_Nom As String
    Private m_Utilisateurs As New List(Of Utilisateur)
    Private m_Historique As New Queue(Of String())
    Private m_HistoriqueCapacity As Integer = 10
    Private m_UsersLimit As Integer

    Public ReadOnly Property CreatedBy As String
        Get
            Return m_CreatedBy
        End Get
    End Property

    Public ReadOnly Property Nom As String
        Get
            Return m_Nom
        End Get
    End Property

    Public ReadOnly Property UsersCount As Integer
        Get
            Return m_Utilisateurs.Count
        End Get
    End Property

    Public ReadOnly Property Utilisateurs As List(Of Utilisateur)
        Get
            Return m_Utilisateurs
        End Get
    End Property

    Public ReadOnly Property UsersLimit As Integer
        Get
            Return m_UsersLimit
        End Get
    End Property

    Public Sub New(nom As String, Optional createdBy As String = "JuneLive", Optional usersLimit As Integer = 30)
        m_Nom = nom
        m_CreatedBy = createdBy
        m_UsersLimit = usersLimit
    End Sub

    Public Sub SendAll(data() As String)
        If data.Count >= 1 AndAlso Val(data(0)) = 70 Then
            m_Historique.Enqueue(data)

            If m_Historique.Count > m_HistoriqueCapacity Then
                m_Historique.Dequeue()
            End If
        End If

        For Each u In m_Utilisateurs
            u.SendData(data)
        Next
    End Sub

    Public Sub SendHistorique(u As Utilisateur, Optional prependData() As String = Nothing)
        Dim data As New List(Of String())

        If Not IsNothing(prependData) Then
            data.Add(prependData)
        End If

        data.AddRange(m_Historique)

        Threading.Thread.Sleep(500)
        u.SendData(data.ToArray)
    End Sub

    'Public Sub sendAllMod(data() As String)
    '    For Each u In m_Utilisateurs
    '        If u.UserLevel = UserLevel.Moderateur OrElse u.UserLevel = UserLevel.Administrateur Then
    '            u.SendData(data)
    '        End If
    '    Next
    'End Sub
End Class
